{% load static %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"zh-hans" }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{% if page_title %}{{ page_title }} - {% endif %}水稻种植管理系统{% endblock %}</title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">

    <link rel="stylesheet" href="{% static 'css/custom_styles.css' %}"> {# Create this file later #}

    <style>
        /* Minimal overrides for demonstration */
        body {
            padding-top: 5rem; /* Adjust for fixed navbar height */
            background-color: #f8f9fa; /* Light background */
        }
        .navbar {
            box-shadow: 0 2px 4px rgba(0,0,0,.1);
        }
        .card {
             margin-bottom: 1.5rem;
             box-shadow: 0 1px 3px rgba(0,0,0,.1);
        }
        .list-group-item-action:hover {
            background-color: #e9ecef;
        }
        /* Style required fields in forms */
        .form-label.required::after {
            content: " *";
            color: red;
        }
    </style>
    {% block extra_head %}{% endblock %}
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-dark bg-success fixed-top">
        <div class="container-fluid">
            <a class="navbar-brand" href="{% url 'home' %}"><i class="bi bi-broadcast"></i> 稻田管家</a> {# Example Icon #}
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#mainNavbar" aria-controls="mainNavbar" aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="mainNavbar">
                <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                    {% if user.is_authenticated %}
                    <li class="nav-item">
                        <a class="nav-link {% if request.resolver_match.app_name == 'field_management' %}active{% endif %}" href="{% url 'field_management:field_list' %}"><i class="bi bi-map"></i> 田块管理</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link {% if request.resolver_match.app_name == 'planting_records' %}active{% endif %}" href="{% url 'planting_records:record_list' %}"><i class="bi bi-calendar-check"></i> 种植记录</a>
                    </li>
                    <li class="nav-item"><a class="nav-link" href="#"><i class="bi bi-thermometer-half"></i> 天气</a></li>
                     <li class="nav-item"><a class="nav-link" href="#"><i class="bi bi-people"></i> 社区</a></li>
                     <li class="nav-item"><a class="nav-link" href="#"><i class="bi bi-question-circle"></i> 求助</a></li>
                     <li class="nav-item"><a class="nav-link" href="#"><i class="bi bi-journal-text"></i> 记事本</a></li>
                    {% endif %}
                </ul>
                <ul class="navbar-nav ms-auto">
                     {% if user.is_authenticated %}
                        <li class="nav-item dropdown">
                          <a class="nav-link dropdown-toggle" href="#" id="userMenuDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                            <i class="bi bi-person-circle"></i> {{ user.username }}
                          </a>
                          <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="userMenuDropdown">
                            <li><a class="dropdown-item" href="#"><i class="bi bi-person-badge"></i> 个人资料</a></li>
                            <li><a class="dropdown-item" href="{% url 'admin:index' %}"><i class="bi bi-gear"></i> 后台管理</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li>
                                <form id="logout-form" method="post" action="{% url 'logout' %}">
                                    {% csrf_token %}
                                    <button type="submit" class="dropdown-item text-danger"><i class="bi bi-box-arrow-right"></i> 退出登录</button>
                                </form>
                            </li>
                          </ul>
                        </li>
                    {% else %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'login' %}"><i class="bi bi-box-arrow-in-right"></i> 登录</a>
                        </li>
                        {# Add registration link if you implement registration #}
                        {# <li class="nav-item"><a class="nav-link" href="{% url 'register' %}">注册</a></li> #}
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>

    <main class="container mt-4">
        {% if messages %}
            {% for message in messages %}
                <div class="alert alert-{{ message.tags|default:'info' }} alert-dismissible fade show" role="alert">
                     <i class="bi {% if message.tags == 'success' %}bi-check-circle-fill{% elif message.tags == 'error' %}bi-x-octagon-fill{% elif message.tags == 'warning' %}bi-exclamation-triangle-fill{% else %}bi-info-circle-fill{% endif %} me-2"></i>
                    {{ message }}
                    <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                </div>
            {% endfor %}
        {% endif %}

        {% block content %}
        {% endblock %}
    </main>

    <footer class="mt-5 py-3 bg-light text-center text-muted">
        <div class="container">
             &copy; {% now "Y" %} 水稻种植管理系统. All rights reserved.
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>

    {% block extra_js %}{% endblock %}
</body>
</html>